<?php

namespace apiend\modules\trade\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\trade\models\PaymentOrderSearch;

/**
 * 调用支付相关接口
 * Order controller for the `trade` module
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class PaymentController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['POST']
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 获取待支付订单内容
     * @return string
     */
    public function actionOrder() {
        Yii::error([
            Yii::$app->request->post(),
            $this->uid,
        ]);
        $model = new PaymentOrderSearch();
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            return $model->dumpError('订单信息获取失败');
        }
        return $model->save();
    }

}
